package com.guaju.yueshangLife.activity.setting;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.base.BaseActivity;
import com.guaju.yueshangLife.databinding.ActivityEditNickNameBinding;
import com.guaju.yueshangLife.net.ApiEntity;
import com.guaju.yueshangLife.textwatcher.SimpleTextWatcher;

public class EditNickNameActivity extends BaseActivity {
    private String correctNickname;
    private ActivityEditNickNameBinding binding;

    @Override
    protected void loadViewLayout() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_edit_nick_name);

    }

    @Override
    protected void bindViews() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    @Override
    protected void setListener() {
        binding.etNewNick.addTextChangedListener(new SimpleTextWatcher() {


            @Override
            protected void afterTxtChanged(Editable s) {
                correctNickname = binding.etNewNick.getText().toString().trim();
                if (TextUtils.isEmpty(correctNickname)) {
                    binding.btSubmit.setBackgroundResource(R.drawable.shape_login_enable_bg);
                    binding.flClear.setVisibility(View.VISIBLE);
                } else {
                    binding.btSubmit.setBackgroundResource(R.drawable.shape_login_unable_bg);
                    binding.flClear.setVisibility(View.INVISIBLE);
                }

            }
        });
        binding.btSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                correctNickname = binding.etNewNick.getText().toString().trim();
                if (!TextUtils.isEmpty(correctNickname)) {

//                        提交新用户名
                    ApiEntity.updateMineInfoUsername(correctNickname);
                    finish();
                }
            }
        });
        binding.flClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                correctNickname = binding.etNewNick.getText().toString().trim();
                if (!TextUtils.isEmpty(correctNickname)) {
                    binding.etNewNick.setText("");
                }
            }
        });


    }
}
